package com.clstu.dao_.testdao;

import com.clstu.dao_.dao.ActorDAO;
import com.clstu.utils.Actor;
import org.testng.annotations.Test;

import java.util.List;

/**
 * 测试ActorDao的使用//
 * 建立连接和关闭资源都已经通过自己写好的攻击类来完成了,
 * 我们只需要写sql语句得到结果就行了
 */
public class TestActorDao {
    @Test//测试ActorDao查询sql语句的使用
    public void method(){
        ActorDAO actorDAO = new ActorDAO();

        String sql = "select * from actor where id > ?";
        List<Actor> actors = actorDAO.queryMany(sql, Actor.class, 0);
        System.out.println("查询多行============");
        for (Actor actor : actors) {
            System.out.println(actor);
        }

        String sql1 = "select name,birthday from actor where id = ?";
        Actor actor = actorDAO.querySingle(sql, Actor.class, 1);
        System.out.println("查询单行============");
        System.out.println(actor);

        String sql2="select name from actor where id = ?";
        Object o = actorDAO.queryScalar(sql2, 1);//这里需要注意有几个?就给几个可变参数!!!!
        System.out.println("单行单列查询===========");
        System.out.println(o);
    }
    @Test//测试ActorDao(dml)sql语句的使用
    public void method1(){
        ActorDAO actorDAO = new ActorDAO();
//        String sql = "insert into actor values (?,?,?,?)";//增
//        String sql1 = "delete from actor where id = ?";//删
        String sql2= "update actor set name = ? where id =?";//改
        int i = actorDAO.update(sql2,"彭于晏",4);
        System.out.println(i>0?"操作成功":"未受影响");
    }
}
